using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;
using BL.DataAccess;

namespace zCO
{
    public static class BackUpDB
    {
        public static void Create()
        {
            try
            {
                Thread th1 = new Thread(new ThreadStart(CreateBackUP));
                th1.Start();
            }
            catch
            {


            }

        }
        private static void CreateBackUP()
        {

            if (!Directory.Exists("C:\\backUpDB"))
            {
                Directory.CreateDirectory("C:\\backUpDB");
            }
            string uncompressed = "C:\\backUpDB" + "\\db" + DateTime.Now.ToString("dd-MM-yyyy") + ".mdb";


            string backup = "C:\\backUpDB" + "\\db" + DateTime.Now.ToString("dd-MM-yyyy") + ".mdb" + ".gz";
            

            if (!File.Exists(backup))
            {
                try
                {
                    File.Copy(Configuration.Current.DataBasePath, uncompressed, true);

                    GZip.Compress(uncompressed, backup);
                    File.Delete(uncompressed);
                    if (DateTime.Today.Day == 9 || DateTime.Today.Day == 20 || DateTime.Today.Day == 27)
                    {

                        Mailing.SendMail("Base de Datos de prodentis del " + DateTime.Today.ToShortDateString(), "...", "development@zetasoft.com.ar", "marianomiani@gmail.com", backup);
                    }
                }
                catch (Exception)
                {
                    //No encontro la ruta, ignoro el error no se realiza la copia de la base de datos
                   
                }
              
            }
        }

    }

}